package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.StationEntity;
import com.my12306.train.model.vo.StationVo;
import com.my12306.train.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;

/**
 * 车站基本信息表
 *
 * @author ËÕÄÁÏ¦
 */
@RestController
@RequestMapping("/station")
public class StationController {
    @Autowired
    private StationService stationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public ResponseData list(PageVo pageVo) {
        PageUtils page = stationService. findAllByPage(pageVo);
        System.out.println(page);
        return ResponseData.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{stationId}")
    public ResponseData info(@PathVariable("stationId") Long stationId) {
        StationEntity station = stationService.getById(stationId);

        return ResponseData.ok().put("station", station);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ResponseData save(@RequestBody StationVo stationVo) {
        stationService.saveStation(stationVo);

        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public ResponseData update(@RequestBody StationVo stationVo) {
        stationService.updateStationById(stationVo);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody Long[] stationIds) {
        stationService.removeByIds(Arrays.asList(stationIds));

        return ResponseData.ok();
    }

}
